package com.xgd.phylw.service.impl;

import com.xgd.phylw.bean.Schedule;
import com.xgd.phylw.dto.Hall_ScheduleDto;
import com.xgd.phylw.mapper.ScheduleMapper;
import com.xgd.phylw.service.ScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Author:flyyoung
 * Date:2021/6/3 9:27
 * Desc:
 **/
@Service
public class ScheduleServiceImpl implements ScheduleService {
    @Autowired
    ScheduleMapper scheduleMapper;
    public List<Hall_ScheduleDto> selectSchedule(int movieId) {
        Schedule schedule = new Schedule();
        if(movieId != 0) {
            schedule.setMovieId(movieId);
        }
        List<Hall_ScheduleDto> list = new ArrayList<Hall_ScheduleDto>();
        List<Schedule> schedules = scheduleMapper.selectAllSchedule(schedule);
        for (Schedule s:schedules){
            Hall_ScheduleDto hs = new Hall_ScheduleDto();
            hs.setScheduleId(s.getScheduleId());
            hs.setMoviePrise(s.getMoviePrise());
            hs.setBeginDate(s.getBeginDate());
            hs.setBeginHour(s.getBeginHour());
            hs.setBeginMinute(s.getBeginMinute());
            hs.setMovieId(s.getMovieId());
            hs.setHallId(s.getHallId());
            hs.setHallName(s.getHall().getHallName());
            hs.setHallSeats(s.getHall().getHallSeats());
            hs.setHallDescribe(s.getHall().getHallDescribe());
            list.add(hs);
        }
        return list;
    }

    public Schedule selectByPrimaryKey(Integer scheduleId) {
        return scheduleMapper.selectByPrimaryKey(scheduleId);
    }

    public int deleteScheduleByPrimaryKey(Schedule schedule) {
        return scheduleMapper.updateSetPrise(schedule);
    }

    public List<Schedule> selectTotalSeats() {
        return scheduleMapper.selectTotalSeats();
    }

    public int insert(Schedule schedule) {
        return scheduleMapper.insert(schedule);
    }
}
